package com.atguigu.fruit.severlet;

import com.atguigu.fruit.dao.FruitDao;
import com.atguigu.fruit.dao.impl.FruitDaoImpl;
import com.atguigu.fruit.pojo.Result;
import com.atguigu.fruit.util.GsonUtil;
import com.atguigu.fruit.util.RespUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/delete")
public class DelServlet extends HttpServlet {
    FruitDao fruitDao = new FruitDaoImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer fid = Integer.parseInt(req.getParameter("fid"));

        fruitDao.delFruitbyFid(fid);
        Result success = Result.success();
        String json = GsonUtil.toJson(success);
        RespUtil.resp(resp, json);

    }
}
